package com.twu.biblioteca.models.services;

import com.twu.biblioteca.models.entities.User;

import java.util.ArrayList;
import java.util.List;

public class UserService {
    private static List<User> users = new ArrayList<User>();
    public static User currentUser = null;

    public static boolean add(User user) {
        return users.add(user);
    }

    public static boolean login(String name, String password) {
        User user = findUserByName(name);
        if (user != null) {
            currentUser = user;
            return user.getPassword().equals(password);
        } else {
            return false;
        }
    }

    public static User findUserByName(String name) {
        for (User user : users) {
            if (user.getName().equals(name)) {
                return user;
            }
        }
        return null;
    }
}
